//
//  DHHomeViewModel.m
//  精品酒店
//
//  Created by DIANGHONG on 2018/5/7.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "DHHomeViewModel.h"

@implementation DHHomeViewModel

- (void)setHomeDatas:(DHHomeDataModel *)homeDatas
{
    _homeDatas = homeDatas;
    
    if (homeDatas.qq) {
        DHNetworkManager.shareManager.qq = homeDatas.qq;
    }
}
/* 加载首页订单列表 **/
- (void)loadHomeStatusListWithWithPullUP:(BOOL)pullup page:(int)page
                                lng:(NSString *)lng
                                lat:(NSString *)lat
                          area_name:(NSString *)area_name
                        FiniedBlock:(void(^)(BOOL hasMore ,BOOL isSuccess))finiedBlock
{
    if (pullup) {
        page++;
        if (self.listModel.hasmore) {
            finiedBlock(false,false);
            return;
        }
        if (page > self.listModel.page_total.intValue + 1) {
            finiedBlock(false,false);
            return;
        }

    }
    NSLog(@"%@",area_name);
    
    [DHNetworkManager.shareManager requestHomeListWithPage:[NSString stringWithFormat:@"%d",page] lng:lng lat:lat area_name:area_name params:nil completion:^(id json, BOOL isSuccess)
     {
         if (!isSuccess) {
             finiedBlock(isSuccess,false);
             return ;
         }
         if (json[@"datas"][@"error"]) {
             finiedBlock(false,false);
             return;
         }
         if (pullup) {
             self.listModel = [DHOrderListModel yy_modelWithJSON:json];
             self.taskList = [self.taskList arrayByAddingObjectsFromArray:[NSArray yy_modelArrayWithClass:[DHOrderModel class] json:json[@"datas"][@"list"]]];
         }else{
             self.listModel = [DHOrderListModel yy_modelWithJSON:json];
            self.taskList = [NSArray yy_modelArrayWithClass:[DHOrderModel class] json:json[@"datas"][@"list"]];
         }
       
         finiedBlock(true,isSuccess);
     }];
}

//- (void)loadMoreDateWithPage:(int)page
//                         lng:(NSString *)lng
//                         lat:(NSString *)lat
//                   area_name:(NSString *)area_name
//                 FiniedBlock:(void(^)(BOOL isSuccess))finiedBlock
//{
//    if (page >= self.listModel.page_total.intValue) {
//        finiedBlock(false);
//        return;
//    }
//
//    [DHNetworkManager.shareManager requestHomeListWithPage:[NSString stringWithFormat:@"%d",page]
//                                                       lng:lng lat:lat
//                                                 area_name:area_name
//                                                completion:^(id json, BOOL isSuccess)
//     {
//         if (!isSuccess) {
//             finiedBlock(isSuccess);
//             return ;
//         }
//         if (json[@"datas"][@"error"]) {
//             finiedBlock(false);
//             return;
//         }
//
//         self.listModel = [DHOrderListModel yy_modelWithJSON:json];
//         NSArray *array = [self.listModel.list arrayByAddingObjectsFromArray:[NSArray yy_modelArrayWithClass:[DHOrderModel class] json:json[@"datas"][@"list"]]];
//
//         finiedBlock(isSuccess);
//     }];
//}


/* 加载首页数据 **/
- (void)loadHomeDataWithFiniedBlock:(void(^)(BOOL isSuccess))finiedBlock
{
    
    [DHNetworkManager.shareManager requestHomeDatasWithCompletion:^(DHHomeDataModel *datasModel, BOOL isSuccess) {
        
        if (!isSuccess) {
            finiedBlock(isSuccess);
        }
        
        self.homeDatas = datasModel;
        finiedBlock(isSuccess);
    }];
}

- (NSInteger)calcRowHeightWithSection:(NSInteger)section
{
    
    switch (section) {
        case 0:
            return 250;
            break;
        case 1:
            return 150;
            break;
        default:
            return 190;
            break;
    }
}

@end
